package com.yunche.yunchebusiness.ui.activity.system

import android.os.Bundle
import com.yunche.yunchebusiness.R
import com.yunche.yunchebusiness.base.BaseActivity
import com.yunche.yunchebusiness.common.CommonDialog
import com.yunche.yunchebusiness.common.Constant
import com.yunche.yunchebusiness.entity.TenantInfoEntity
import com.yunche.yunchebusiness.mvp.contract.TenantContract
import com.yunche.yunchebusiness.mvp.presenter.TenantPresenter
import com.yunche.yunchebusiness.ui.activity.finance.MyCardActivity
import com.yunche.yunchebusiness.utils.ToastyUtils
import kotlinx.android.synthetic.main.activity_tenant_info.*


class TenantInfoActivity : BaseActivity(), TenantContract.View {

    private var tenantEntity: TenantInfoEntity? = null

    private val mPresenter by lazy {
        TenantPresenter()
    }

    override fun setLayout(): Int = R.layout.activity_tenant_info

    override fun getTenantSuccess(tenantEntity: TenantInfoEntity) {

        this.tenantEntity = tenantEntity

        tv_tenant_name.text = tenantEntity.tenant.name

        tv_tenant_contact_name.text = tenantEntity.tenant.contactName
        tv_tenant_contact_mobile.text = tenantEntity.tenant.contactMobile
        tv_tenant_contact_position.text = tenantEntity.tenant.contactPosition
        var province = tenantEntity.tenant.parentAreaName
        var city = tenantEntity.tenant.areaName
        tv_tenant_address.text = "$province $city - ${tenantEntity.tenant.address}"

        tv_tenant_bank_count.text = "${tenantEntity.accountList.size} 张"


        var partnerList = ""
        for (partner in tenantEntity.partnerList) {
            partnerList += partner.partnerName + "\n"
        }
        tv_tenant_partner.text = partnerList

    }


    override fun showLoading() {
        CommonDialog.showLoading(mContext!!, Constant.Loading)
    }

    override fun hideLoading() {
        CommonDialog.cancle()
    }

    override fun showError(msg: String) {
        ToastyUtils.showError(msg)
    }

    override fun initView() {
        mPresenter.attachView(this)
    }

    override fun initData() {
        mPresenter.getTenantInfo()
    }

    override fun initEvent() {
        linlay_area.setOnClickListener {
            var bundle = Bundle()
            bundle.putSerializable("tenant", tenantEntity)
            openActivityWithBundle(ChangeAddressActivity::class.java, bundle)
        }

        linlay_bank_list.setOnClickListener {
            openActivity(MyCardActivity::class.java)
        }
    }

    override fun onRestart() {
        super.onRestart()
        initData()
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter.detachView()
    }

}
